package cn.school.iot.service.impl;

import cn.school.common.utils.SysUserUtils;
import cn.school.iot.dao.FaceGateRuleDeviceDao;
import cn.school.iot.service.FaceGateRuleDeviceService;
import cn.school.iot.vo.FaceGateRuleDevice;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @Description: TODO(一句话描述该类的功能)
 * @ClassName: FaceGateRuleDeviceServiceImpl
 * @Author: tzw
 * @Date: 2024/4/2 8:59
 */
@Service
public class FaceGateRuleDeviceServiceImpl extends ServiceImpl<FaceGateRuleDeviceDao, FaceGateRuleDevice> implements FaceGateRuleDeviceService {
    @Override
    public boolean addOrUpdateDeviceRule(List<Map> map) {
        List<FaceGateRuleDevice> vo = new ArrayList<>();
        for (Map<String, String> faceGateMap : map) {
            Set<Map.Entry<String, String>> entries = faceGateMap.entrySet();
            for (Map.Entry<String, String> entry : entries) {
                String value = entry.getValue();
                String[] split = value.split("-");
                FaceGateRuleDevice faceGateRuleDevice = new FaceGateRuleDevice();
                faceGateRuleDevice.setDeviceId(Long.valueOf(entry.getKey()));
                faceGateRuleDevice.setDeviceRuleIndex(split[0]);
                faceGateRuleDevice.setFaceGateRuleId(Long.valueOf(split[1]));
                faceGateRuleDevice.setCreateTime(new Date());
                faceGateRuleDevice.setTenantId(String.valueOf(split[2]));
                faceGateRuleDevice.setCreateBy(String.valueOf(split[2]));
                vo.add(faceGateRuleDevice);

            }
        }
        boolean result = super.saveOrUpdateBatch(vo);
        return result;
    }
}
